﻿using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using XJay.Scheduler.Model;

namespace XJay.Scheduler.Middleware
{
    public class AppResultHandler : ActionFilterAttribute
    {
        public override void OnActionExecuted(ActionExecutedContext context)
        {
            if(context.Exception != null)
            {
                return;
            }
            var result = (ObjectResult)context.Result;
            context.Result = new JsonResult(new ResposeData() { 
                Data = result.Value ?? null
            });
        }
    }
}
